package com.example.work3.repository;
import com.example.work3.entity.User;
import jakarta.transaction.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;

import java.util.List;


public interface UserRepository extends CrudRepository<User,String>, PagingAndSortingRepository<User,String> {
   User findByAccountAndPassword(String Account,String Password);
   @Modifying
   @Transactional
   @Query("UPDATE user u SET u.password = ?2 WHERE u.account = ?1")
   Integer updateUserByAccount(String account, String password);
   //角色和用户名
   Page<User> findAllByAccountAndRole(String account, Integer role, Pageable pageable);
   //角色
   Page<User> findAllByRole(Integer role, Pageable pageable);
   //用户名
   Page<User> findAllByAccount(String account, Pageable pageable);
   @Transactional
   @Modifying
   @Query("DELETE FROM user u WHERE u.account = ?1")
   Integer deleteUserByAccount(String account);

}
